package com.yhn.bff.driver.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.yhn.bff.driver.dto.req.RegisterNewDriverReqDTO;
import com.yhn.bff.driver.feign.DrServiceApi;
import com.yhn.bff.driver.service.DriverService;
import com.yhn.hxds.common.exception.BusinessException;
import com.yhn.hxds.common.model.BaseResponse;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author yhn
 * @version 1.0
 * @description
 * @date 2024/9/16 13:13
 */
@Service
public class DriverServiceImpl implements DriverService {
    @Resource
    private DrServiceApi drServiceApi;
    @Override
    @Transactional
    public String registerNewDriver(RegisterNewDriverReqDTO requestParam) {
        BaseResponse<String> baseResponse = drServiceApi.registerNewDriver(requestParam);
        String id = baseResponse.getMessage();
        if("500".equals(baseResponse.getCode())){
            throw new BusinessException("该微信无法注册");
        }
        //使用satoken执行登录，缓存id
        StpUtil.login(id);
        //生成token
        return StpUtil.getTokenInfo().getTokenValue();

    }
}
